﻿Public Class GPX
    Dim sp1 = 1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp1 = 1 Then
            Label3.Text = "0"
            Button1.Text = "Aufnahme-Stop"
            ListBox1.Items.Clear()
            ListBox1.Items.Add("<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & " ?>")
            ListBox1.Items.Add("<gpx")
            ListBox1.Items.Add("version=" & Chr(34) & "1.0" & Chr(34) & "")
            ListBox1.Items.Add("creator=" & Chr(34) & "GPS Status - Freeware" & Chr(34) & "")
            ListBox1.Items.Add("xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & "")
            ListBox1.Items.Add("xmlns=" & Chr(34) & "http://www.topografix.com/GPX/1/0" & Chr(34) & "")
            ListBox1.Items.Add("xsi:schemaLocation=" & Chr(34) & "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd" & Chr(34) & ">")
            ListBox1.Items.Add("<time>" & My.Computer.Clock.LocalTime.Year & "-" & My.Computer.Clock.LocalTime.Month & "-" & My.Computer.Clock.LocalTime.Day & "T" & My.Computer.Clock.LocalTime.Hour & ":" & My.Computer.Clock.LocalTime.Minute & ":" & My.Computer.Clock.LocalTime.Second & "Z</time>")
            ListBox1.Items.Add("<trk>")
            ListBox1.Items.Add("<name>" & TextBox1.Text & "</name>")
            ListBox1.Items.Add("<trkseg>")
            sp1 = 0
        Else
            ListBox1.Items.Add("</trkseg>")
            ListBox1.Items.Add("</trk>")
            ListBox1.Items.Add("</gpx>")
            sp1 = 1
            Button1.Text = "Aufnahme-Start and Neu"
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sfd As New SaveFileDialog
        sfd.InitialDirectory = "C:\"
        sfd.Filter = "GPS-Datei (*.GPX)|*.gpx"
        sfd.Title = "Wählen Sie eine Datei zum Speichern aus"
        If sfd.ShowDialog() = DialogResult.OK Then
            Using strw As New IO.StreamWriter(New IO.FileStream(sfd.FileName, IO.FileMode.Create))
                For Each item As String In ListBox1.Items : strw.WriteLine(item) : Next : strw.Close()
            End Using

        Else
            MsgBox("Abbruch")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ListBox1.Items.Clear()
    End Sub
    Dim up1
    Public Sub tick(ByVal lat, ByVal lon, ByVal up)
        up1 = up
        If sp1 = 0 Then

            If lat = "" Then

            Else
                If lon = "" Then

                Else

                    If up1 = "" Then

                    Else


                        ListBox1.Items.Add("<trkpt lat= " & Chr(34) & "" & lat & "" & Chr(34) & "  lon= " & Chr(34) & "" & lon & "" & Chr(34) & " >")
                        ListBox1.Items.Add("<ele>" & up1 & "</ele>")
                        ListBox1.Items.Add("<time>" & My.Computer.Clock.LocalTime.Year & "-" & My.Computer.Clock.LocalTime.Month & "-" & My.Computer.Clock.LocalTime.Day & "T" & My.Computer.Clock.LocalTime.Hour & ":" & My.Computer.Clock.LocalTime.Minute & ":" & My.Computer.Clock.LocalTime.Second & "Z</time>")
                        ListBox1.Items.Add("</trkpt>")
                        Label3.Text = Label3.Text + 1


                    End If

                End If
            End If






        Else
        End If

    End Sub
    
    Private Sub GPX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TopMost = True
    End Sub
End Class